package com.huawei.appgallery.foundation.ui.framework.widget.button;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.ui.css.CSSRule;
import com.huawei.appgallery.foundation.ui.css.CSSViewProxy;
import com.huawei.appgallery.foundation.ui.css.RenderListener;
import com.huawei.appgallery.foundation.ui.css.adapter.CSSPropertyName;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSMonoColor;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSValue;
import java.util.ArrayList;
import java.util.List;
import o.cjz;
import o.ckc;
import o.ckd;
import o.cke;
import o.ckf;
import o.ckg;
import o.cki;
import o.ckk;
import o.ckt;
import o.dky.a;
import o.dky.j;
import o.Logger;
import o.epv;
import o.MinimumFactory;
import o.evf;
import o.fle;

public class DownloadButton extends BaseDownloadButton implements RenderListener, OnClickListener {
    static final List<DownloadButton> ˊ = new ArrayList();
    private static String ॱॱ = "DownloadButton";
    private ckc ʻ;
    private boolean ʼ;
    protected ckd ʽ;
    protected CharSequence ˋ;
    protected cke ˎ;
    protected BaseDistCardBean ˏ;
    protected int ॱ;
    private cki ॱˊ;
    private boolean ᐝ;

    static {
        ckf ˋ = ButtonFactory.ˋ();
        if (ˋ == null) {
            Logger.e(ॱॱ, "button not init,can not use");
        } else {
            ˋ.ॱ();
        }
    }

    public DownloadButton(Context context) {
        this(context, null);
    }

    public DownloadButton(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public DownloadButton(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˎ = cke.DOWNLOAD_APP;
        this.ˋ = "";
        this.ॱ = -1;
        this.ʽ = new ckd();
        this.ʼ = false;
        this.ᐝ = false;
        ˋॱ();
    }

    private static void ˎ(DownloadButton downloadButton) {
        if (!ˊ.contains(downloadButton)) {
            ˊ.add(downloadButton);
        }
    }

    private static void ॱ(DownloadButton downloadButton) {
        ˊ.remove(downloadButton);
    }

    private void ˋॱ() {
        setOnClickListener(new ckt(this, 650));
        this.ᐝ = false;
        setEnabled(true);
        setClickable(true);
        cjz.ˎ(ˊॱ());
        this.ʻ = ButtonFactory.ˏ(getClass(), getContext());
        this.ʽ = this.ʻ.ˋ();
    }

    protected void ˏ(boolean z) {
        setEnabled(z);
    }

    protected void ˋ(boolean z) {
        super.setEnabled(z);
    }

    public void setButtonStyle(ckd o_ckd) {
        this.ʽ = o_ckd;
        invalidate();
    }

    public void setDownloadProgress(int i) {
        this.ॱ = i;
        this.ˎ = cke.PAUSE_DOWNLOAD_APP;
        if (!isEnabled()) {
            ˏ(true);
        }
        setProgress(this.ॱ);
        this.ˋ = MinimumFactory.setMinimumFt(this.ॱ);
        setText(this.ˋ);
        setContentDescription(getResources().getString(j.ॱʽ) + this.ˋ);
    }

    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        ॱ(this);
    }

    public cke ॱ() {
        this.ˎ = cke.DOWNLOAD_APP;
        ai_();
        if (!this.ʼ) {
            ˏ(true);
        }
        if (this.ˏ == null) {
            Logger.e(ॱॱ, "refreshStatus error:cardBean is null");
            return cke.APP_INVALIED;
        } else if (this.ˏ.ॱـ() != null || this.ˏ.ͺ() == 1 || this.ˏ.ͺ() == 14) {
            ckg ˎ = this.ʻ.ˎ(this.ˏ);
            this.ˎ = ˎ.ॱ();
            this.ˋ = ˎ.ˋ();
            this.ॱ = ˎ.ˎ();
            ckk ॱ = this.ʽ.ॱ(this.ˎ);
            ˋ(ॱ);
            ˋ(ॱ.ˏ(), this.ॱ);
            this.ˋ = this.ʻ.ˋ(this.ˏ, this.ˎ, this.ˋ, ˊॱ());
            if (ॱ.ˊ() != 0) {
                setTextColor(ॱ.ˊ());
            }
            setText(this.ˋ);
            ˏ();
            ˎ();
            setContentDescription(this.ˋ);
            return this.ˎ;
        } else {
            Logger.e(ॱॱ, "refreshStatus error:getPackage_ is null");
            return cke.APP_INVALIED;
        }
    }

    private void ͺ() {
        if (this.ˏ != null && (this.ˏ.ˌ() & 1) != 0) {
            setButtonDisable();
        }
    }

    private void ʻॱ() {
        if (this.ˏ != null && (this.ˏ.ˌ() & 2) != 0) {
            setButtonDisable();
        }
    }

    private void ॱᐝ() {
        if (this.ˏ != null && (this.ˏ.ˌ() & 7) != 0) {
            setButtonDisable();
        }
    }

    protected void ˏ() {
        if (this.ˎ == cke.PAUSE_DOWNLOAD_APP || this.ˎ == cke.MEGER_DIFF_APP) {
            ˎ(this);
        } else {
            ॱ(this);
        }
    }

    public void onClick(View view) {
        this.ʻ.ˋ(this, this.ˏ, this.ˎ);
    }

    public boolean onRenderReady(CSSViewProxy cSSViewProxy) {
        CSSRule rule = cSSViewProxy.getRule();
        if (rule.getStyleDeclaration() != null) {
            CSSValue propertyValue = rule.getStyleDeclaration().getPropertyValue(CSSPropertyName.FONT_COLOR);
            if (propertyValue instanceof CSSMonoColor) {
                this.ᐝ = true;
                CSSMonoColor cSSMonoColor = (CSSMonoColor) propertyValue;
                this.ʽ = this.ʻ.ˎ(cSSMonoColor.getColor(), cSSMonoColor.getColor());
            }
        }
        return false;
    }

    public void setButtonDisable() {
        if (this.ʽ == null || !this.ᐝ) {
            ʻ();
        } else {
            ckk ॱ = this.ʽ.ॱ();
            setTextColor(ॱ.ˊ());
            setProgressDrawable(ॱ.ˏ());
        }
        ˋ(false);
    }

    public void setEnabled(boolean z) {
        if (z) {
            ckk ॱ = this.ʽ.ॱ(this.ˎ);
            ˋ();
            ˋ(true);
            if (!(ॱ == null || ॱ.ˏ() == null)) {
                setProgressDrawable(ॱ.ˏ());
            }
            if (ॱ != null && ॱ.ˊ() != 0) {
                setTextColor(ॱ.ˊ());
                return;
            }
            return;
        }
        setButtonDisable();
    }

    protected void setTextColor(int i) {
        if (ˊॱ() != null && ˊॱ().getCurrentTextColor() != i) {
            ˊॱ().setTextColor(i);
        }
    }

    protected void setTextSize(int i) {
        if (ˊॱ() != null) {
            ˊॱ().setTextSize((float) epv.ˋ(getContext(), i));
        }
    }

    protected void setProgressDrawable(Drawable drawable) {
        ˋ(drawable, -1);
    }

    protected void ˋ(Drawable drawable, int i) {
        if (i >= 0 && i <= 100) {
            ˏ(1);
            setProgress(i);
        }
        if (drawable != null && ˏॱ() != null) {
            ˏॱ().setProgressDrawable(drawable);
        }
    }

    protected void ˋ(ckk o_ckk) {
        if (o_ckk.ˏ() == null) {
            this.ᐝ = false;
        }
    }

    public void setIsImmersion(boolean z) {
        this.ᐝ = z;
    }

    protected void ˎ() {
        if (ॱˋ()) {
            setButtonDisable();
        } else if (ॱˎ()) {
            ʻॱ();
        } else if (ᐝॱ()) {
            ͺ();
        } else if (cke.FAST_APP == this.ˎ) {
            ॱᐝ();
        }
    }

    private boolean ᐝॱ() {
        return cke.OPEN_APP == this.ˎ || cke.H5_APP == this.ˎ;
    }

    private boolean ॱˎ() {
        return cke.DOWNLOAD_APP == this.ˎ || cke.GOOGLE_PLAY == this.ˎ || cke.DEEPLINK_ORDER == this.ˎ || cke.INSTALL_APP == this.ˎ || cke.UPGRADE_APP == this.ˎ || cke.SMART_UPGRADE_APP == this.ˎ || cke.PRE_DOWNLAD_APP == this.ˎ || cke.NO_APK_APP == this.ˎ || cke.WISH_APP_ADD == this.ˎ || cke.WISH_APP_CHECK == this.ˎ;
    }

    private boolean ॱˋ() {
        return this.ˎ == cke.WAIT_INSTALL_APP || this.ˎ == cke.INSTALLING_APP || this.ˎ == cke.UNINSTALLING_APP || this.ˎ == cke.WAIT_UNINSTALL_APP || this.ˎ == cke.MEGER_DIFF_APP;
    }

    protected void ˋ() {
        if (ˏॱ() != null && ˏॱ().getProgressDrawable() != null && ˊॱ() != null) {
            ˏॱ().getProgressDrawable().setAlpha(255);
            ˊॱ().setAlpha(1.0f);
        }
    }

    protected void ʻ() {
        if (ˏॱ() != null && ˏॱ().getProgressDrawable() != null && ˊॱ() != null) {
            ˏॱ().getProgressDrawable().setAlpha(255);
            ˊॱ().setAlpha(0.38f);
        }
    }

    public String ॱॱ() {
        if (this.ˏ != null) {
            return this.ˏ.ॱـ();
        }
        return "";
    }

    public void setParam(BaseDistCardBean baseDistCardBean) {
        this.ˏ = baseDistCardBean;
    }

    public void setEventProcessing(boolean z) {
        this.ʼ = z;
    }

    public boolean ʼ() {
        return this.ʼ;
    }

    public cki ʽ() {
        return this.ॱˊ;
    }

    public void setDownloadListener(cki o_cki) {
        this.ॱˊ = o_cki;
    }

    public void ˏ(int i) {
        super.ˏ(i);
        ʿ();
    }

    public void onRestoreInstanceState(Parcelable parcelable) {
        super.onRestoreInstanceState(parcelable);
        if (ॱˊ() != 0) {
            ʿ();
        }
    }

    private void ʿ() {
        Context context = getContext();
        if (evf.ˊ(this)) {
            ((fle) context).ˊ(ˏॱ(), "progressDrawable", a.ˏˎ);
        }
    }
}
